﻿using UnityEngine;
using System.Collections;
using System;
using Mono.Data.Sqlite;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;

public class StartConnect : MonoBehaviour
{
    private GameObject obj;
    private float nowTime = 0f;

    void Awake()
    {
        obj = GameObject.Find("Cube");
    }

    // Update is called once per frame
    void Update()
    {
        //if(obj) DestroyImmediate(obj);
        //Debug.Log(obj);
    }

    // Use this for initialization
    void Start()
    {
        //gameObject.GetComponent<NetWorkToServer>().ConnectEX("192.168.1.202",12900);
        //Debug.Log("连接");

        //GameObject camera = GameObject.Find("Main Camera");
        //SceneObject so = camera.AddComponent("SceneObject") as SceneObject;
        //so.ObjID = new Point(1,23);
        //Hashtable ht = new Hashtable();
        //ht.Add(so.ObjID, so);
        //Debug.Log((ht[so.ObjID] as SceneObject).ObjID);

        //Debug.Log(ModelLocator.getInstance().test());

        //GameObject obj = GameObject.Find("Main Camera");
        //SceneObject so = obj.AddComponent("SceneObject") as SceneObject;
        //so.configFile = "npc";
        //SceneObject so = obj.GetComponent("SceneObject") as SceneObject;

        //Debug.Log(so.GetProperties("equip_1"));

        //int val = 5;
        //Debug.Log((val&0xFF)<<20);
        //byte b = 5;
        //Debug.Log((b & 0xFF) << 20);

        //Point obId = new Point();
        //obId.SetObjectID(1, 1, 1, 1);
        //Debug.Log(obId.ToString());
        //obId.SetObjectID(1, 2, 2, 1);
        //Debug.Log(obId.ToString());

        //ByteArrayEx byt = new ByteArrayEx();
        //byt.writeInt(12);
        //ByteArrayEx b = new ByteArrayEx(byt.byteArray);
        //Debug.Log(b.readInt());
        //Debug.Log(ByteArrayTool.byteToInt(byt.byteArray));

        //ByteArrayEx byt1 = new ByteArrayEx();
        //byt1.writeFloat(12);
        //Debug.Log(ByteArrayTool.byteTofloat(byt1.byteArray));

        //ByteArrayEx byt = new ByteArrayEx();
        //byt.writeInt(8);
        //byt.writeInt(3);
        //byt.writeInt(4);
        //        MySocket.getInstance().test(byt.byteArray);


        //        ByteArrayEx byte1 = new ByteArrayEx();
        //        byte1.writeMultiByteEx("ab");
        //        //print(byte1.readMultiByte(1));
        //        print(byte1.readMultiByteEx());

        //ByteArrayEx byteArr = new ByteArrayEx();
        //byteArr.writeMultiByteEx("abcdef");
        //print(byteArr.readMultiByteEx());


        //        ByteArrayEx b = new ByteArrayEx();
        //        b.writeWString("我是好人");
        //        print(b.readWString());

        //		string a = "a";
        //		a += "";
        //		a +="b";
        //		a +="c";
        //		a +="d";
        //		a += "";
        //		a += "";
        //		a += "";
        //		
        //		print(a);

        //        ByteArrayEx byt = new ByteArrayEx();
        //        byt.writeInt(4);
        //        byt.writeInt(5);
        //        print(byt.readInt()+" "+byt.readInt());


        //ByteArrayEx byt = new ByteArrayEx();
        //byt.writeMultiByteEx("abcdef");
        //print(byt.readMultiByteEx());


        //        print((int)MySocket.Erro_Socket.CONNECT_CONNECED_ERROR);

        //ByteArrayEx bytArr = new ByteArrayEx();
        //bytArr.writeMultiByteEx("abcd");
        //print(bytArr.readMultiByteEx());

        //ByteArrayEx byteArr = new ByteArrayEx();
        //byteArr.writeWString("我是孤帆");
        //print(byteArr.readWString());

        //Point obId = new Point();
        //obId.SetObjectID(1, 1, 1, 1);
        //Debug.Log(obId.ToString());
        //Debug.Log(obId.QuerySrvId() + " " + obId.QuerySubType() + " " + obId.QueryType());
        //Debug.Log(obId.z);

        //Debug.Log((obId.z & 0xFFFFFFFF).ToString() + "  " + (obId.z >> 32).ToString());

        //Debug.Log(obId.QuerySrvId() + " " + obId.QuerySubType() + " " + obId.QueryType());

        //obId.SetObjectID(1, 2, 2, 1);
        //Debug.Log(obId.ToString());
        //Debug.Log(obId.QuerySrvId() + " " + obId.QuerySubType() + " " + obId.QueryType());
        //Debug.Log(obId.z);

        //Debug.Log((obId.z & 0xFFFFFFFF).ToString() + "  " + (obId.z >> 32).ToString());

        //Debug.Log(obId.QuerySrvId()+" "+obId.QuerySubType() + " " + obId.QueryType());

        //UInt32 n1 = 1;
        //UInt32 n2 = 1;
        //UInt64 index = 1;
        //UInt64 index2 = 1;
        //Debug.Log((UInt64)n1 << 63 | (UInt64)n2);

        //ByteArrayEx arr = new ByteArrayEx();
        //arr.writeInt(1);
        //arr.writeInt(2);
        //arr.writeInt(3);
        //arr.writeInt(4);
        ////arr.readInt();
        //ByteArrayEx arr2 = arr;
        //arr2.writeInt(5);
        //Debug.Log(arr2.length + " " + arr2.position);

        //ModelLocator.getInstance().scene.HandleProperties("name", "gf");
        //BindManage.getInstance().BindProp(ModelLocator.getInstance().scene, "name", this, "changeName");
        //ModelLocator.getInstance().scene.HandlePropertiesEx("name", "gg");

        //        ModelLocator.getInstance().scene.Role.HandleProperties("name", "gf");
        //BindManage.getInstance().BindProp(ModelLocator.getInstance().scene.Role, "name", this, "changeName");
        ////BindManage.getInstance().BindProp(ModelLocator.getInstance().scene.Role, "name", this, "changeName");
        //ModelLocator.getInstance().scene.Role.HandlePropertiesEx("name", "gg");

        //BinaryReaderTool.getInstance().LoadString();
        //Debug.Log(BinaryReaderTool.getInstance().getSwfLangStr("10001"));
        //Debug.Log(BinaryReaderTool.getInstance().getSwfLangStr("30001"));
        //Debug.Log(BinaryReaderTool.getInstance().getSwfLangStr("50004"));
        //Debug.Log(BinaryReaderTool.getInstance().getSwfLangStr("我是测试的"));


        //ArrayList rec = new ArrayList();
        //for (int i = 0; i < 10; i++)
        //{
        //    ArrayList tmp = new ArrayList();
        //    for (int j = 0; j < 10; j++)
        //    {
        //        tmp.Add(j);
        //    }
        //    tmp.TrimToSize();
        //    rec.Add(tmp);
        //}
        //rec.TrimToSize();

        //        string[] roleInfo = SqliteReader.getInstance().getIniVal("TeplatesInfo", "OType", "1", new string[] { "Struct", "Config", "Key" });
        //        InitXML.getInstance().AnalyzeXml(roleInfo[0], roleInfo[1], roleInfo[2] ,"1" , ModelLocator.getInstance().scene.Role);//主角人物的本地初始化//

        //ArrayList arr = new ArrayList();
        //arr.Insert(0,1);
        //        if (arr[0] == null)
        //        {
        //            arr[0] = new ArrayList();
        //        }

        //Point p = new Point();
        //p.z = 1;
        //RoleVo obj = new RoleVo(new Point());
        //obj.ObjID = p;
        //ObjectData od = obj as ObjectData;

        //Debug.Log(od.ObjKey);

        //Record test = new Record("TestRec");
        //ModelLocator.getInstance().scene.HandleProperties("TestRec",test);

        //ArrayList arr = new ArrayList();

        //ArrayList arr1 = new ArrayList();
        //arr1.Add(1);
        //arr1.Add(2);
        //arr1.Add(3);
        //arr1.Add(4);
        //ArrayList arr2 = new ArrayList();
        //arr2.Add(5);
        //arr2.Add(6);
        //arr2.Add(7);
        //arr2.Add(8);
        //arr.Add(arr1);
        //arr.Add(arr2);

        //test.recArr = arr;

        //BindManage.getInstance().BindRecord(ModelLocator.getInstance().scene, "TestRec", this, "addFunc", "removeFunc");
        //BindManage.getInstance().CallRecord(test, 1, arr1, true);


        //string[] roleInfo = SqliteReader.getInstance().getIniVal("TeplatesInfo", "OType", "1", new string[] { "Struct", "Config", "Key" });

        //Debug.Log(roleInfo[0]);

        //ModelLocator.getInstance().scene.HandlePropertiesEx("12345",ModelLocator.getInstance().scene.Role);

        //SceneObject obj = (SceneObject)ModelLocator.getInstance().scene.GetProperties("12345");

        //BindManage.getInstance().BindProp(ModelLocator.getInstance().scene.Role, "name", this, "changeProp");

        //obj.HandlePropertiesEx("name", "gf");

        //loadXML();

        //TestTween();


        //GameObject obj = GameObject.Find("Cube");

        //GameObjectPool.getInstance().InitGameObjectPool(obj, 10, resetGameOj, false);

        //Vector3 pos = new Vector3(1,1,0);

        //GameObject poolObj =  GameObjectPool.getInstance().Spawn(pos);

        //poolObj.name = "123";

        //GameObjectPool.getInstance().Unspawn(poolObj);


        //TestMsgTipsLogic();


        //Hashtable table = new Hashtable();
        //GameObject obj = new GameObject();
        //obj.name = "obj";
        //UILabel label = obj.AddComponent("UILabel") as UILabel;
        //label.text = "label";
        //table.Add(obj.name,obj);

        //GameObject ob = table["obj"] as GameObject;
        //UILabel la = ob.GetComponent<UILabel>();
        //Debug.Log(la.text);


        //GameManage.getInstance();


        //string str = "Npc10001_1";
        //Debug.Log(str.Split(new string[]{ "Npc" },StringSplitOptions.RemoveEmptyEntries)[0]);

        
        //SoundManage.getInstance().playMusic("sz");
        //SoundManage.getInstance().playMusic("0");
        //SoundManage.getInstance().stopBG();


        //BaseObject obj = new BaseObject();
        //ArrayList arr = new ArrayList();
        //arr.Add(1);
        //obj.HandleProperties("test", arr);

        //ArrayList arr2 = obj.GetProperties("test") as ArrayList;
        //arr2.Add(2);
        //Debug.Log(( (ArrayList)obj.GetProperties("test")).Count);


        //Dictionary<int, Dictionary<int, ArrayList>> arr = new Dictionary<int, Dictionary<int, ArrayList>>();
        //Dictionary<int, ArrayList> new1 = new Dictionary<int, ArrayList>();
        //ArrayList list = new ArrayList();
        //list.Add(1);
        //new1.Add(1, list);
        //arr.Add(1, new1);

        //Dictionary<int, Dictionary<int, ArrayList>> arr1 = new Dictionary<int, Dictionary<int, ArrayList>>(arr);
        //Debug.Log(arr[1][1].Count);
        //arr[1][1].Add(2);
        //Debug.Log(arr1[1][1].Count);

        //Debug.Log(arr[1][1].Count);

        //Dictionary<int, ArrayList> arr = new Dictionary<int, ArrayList>();
        //ArrayList list = new ArrayList();
        //list.Add(1);
        //arr.Add(1, list);
        //Debug.Log(arr[1].Count);

        //list.Add(2);
        //arr.Add(1, list);
        //Debug.Log(arr[1].Count);


        //Dictionary<int, int> arr = new Dictionary<int, int>();
        //arr.Add(5, 1);
        //arr.Add(3, 2);
        //arr.Add(1, 3);
        //arr.Add(2, 4);
        //arr.Add(4, 5);

        //foreach (KeyValuePair<int,int> entry in arr)
        //{
        //    Debug.Log(entry.Key);
        //}

        //ArrayList arr = new ArrayList();
        //arr.Add(5);
        //arr.Add(3);
        //arr.Add(1);
        //arr.Add(2);
        //arr.Add(4);
        //arr.Reverse();

        //foreach (int entry in arr)
        //{
        //    Debug.Log(entry);
        //}



        //ModelLocator.getInstance().addEventListener(123, receiveInfo);

        //ModelLocator.getInstance().dispacthEvent(123, new object[] { arr });



        //Dictionary<int, ArrayList> typeFuncArr = new Dictionary<int, ArrayList>();
        //ArrayList arr = new ArrayList();
        //arr.Add(1);
        //typeFuncArr.Add(1, arr);
        //Debug.Log(typeFuncArr[1][0]);

        //typeFuncArr[1][0] = 2;
        //Debug.Log(typeFuncArr[1][0]);

        int val1 = TimeManage.getInstance().addTimeEvent(2, countTime1);
        int val2 = TimeManage.getInstance().addTimeEvent(3, countTime1);
        int val3 = TimeManage.getInstance().addTimeEvent(4, countTime1);
        //Debug.Log(val1 + " " + val2 + " " + val3);
        TimeManage.getInstance().removeTimeEvent(val1);
        int val4 = TimeManage.getInstance().addTimeEvent(5, countTime1);
        int val5 = TimeManage.getInstance().addTimeEvent(6, countTime1);
        //Debug.Log(val4 + " " + val5);
        TimeManage.getInstance().removeTimeEvent(val5);
        int val6 = TimeManage.getInstance().addTimeEvent(7, countTime1);
        int val7 = TimeManage.getInstance().addTimeEvent(8, countTime1);
        //Debug.Log(val6 + " " + val7);


        //for (int i = 90; i < 100;i++ )
        //{
        //    Debug.Log(TimeManage.getInstance().addTimeEvent(i+1, countTime3));
        //}

        //string str = "123";
        //Debug.Log(TimeManage.getInstance().addTimeEvent(3, str, countTime3));


        // Dictionary<int, string> dicA = new Dictionary<int, string>
        // {
        //        {1,"Jack"},
        //        {2,"Loocy"},
        //        {3,"Kitty"}
        // };

        //Dictionary<int, string> dicC = new Dictionary<int, string>(dicA);//方法1
        //Dictionary<int, string> obj = Clone(dicA) as Dictionary<int, string>;//方法2
        //dicA[1] = "sun";
        //foreach (var item in dicA)
        //{
        //    Debug.Log(item.Key + " " + item.Value);
        //}
        //foreach (var item in dicC)
        //{
        //    Debug.Log(item.Key + " " + item.Value);
        //}
        //foreach (var item in obj)
        //{
        //    Debug.Log(item.Key + " " + item.Value);
        //}




    }

    /// <summary>
    /// 得到一个对象的克隆
    /// </summary>
    public static object Clone(object obj)
    {
        MemoryStream memoryStream = new MemoryStream();
        BinaryFormatter formatter = new BinaryFormatter();
        formatter.Serialize(memoryStream, obj);
        memoryStream.Position = 0;
        return formatter.Deserialize(memoryStream);
    }

    private void countTime1(object obj,DispatchEventArgs e)
    {
        int count = (int)e.data[0];
        Debug.Log("countTime1 " + count);
    }
    private void countTime2(object obj, DispatchEventArgs e)
    {
        int count = (int)e.data[0];
        Debug.Log("countTime2 "+count);
        Debug.Log("6=>" + TimeManage.getInstance().addTimeEvent(6, countTime3));
    }
    private void countTime3(object obj, DispatchEventArgs e)
    {
        int count = (int)e.data[0];
        Debug.Log("countTime3 " + count);
        Debug.Log(((ArrayList)e.data[1])[0]);
        Debug.Log(((ArrayList)e.data[1])[3]);
    }


    private void receiveInfo(object obj, DispatchEventArgs e)
    {
        Dictionary<int, int> arr = e.data[0] as Dictionary<int, int>;
        Debug.Log(arr[1]);
    }



    void TestMsgTipsLogic()
    {
        Vector3 pos = new Vector3(2, 1, 0);

        MsgTipsLogic.getInstance().ShowInfo("尝试1", pos, 3.0f);

        /*
        nowTime = Time.realtimeSinceStartup;
        for (int i = 0; i < 100; i++)
        {
            MsgTipsLogic.getInstance().ShowInfo("尝试1", pos, 3.0f);
        }
        Debug.Log(Time.realtimeSinceStartup - nowTime);//0.024


        nowTime = Time.realtimeSinceStartup;
        for (int i = 0; i < 100; i++)
        {
            MsgTipsLogic.getInstance().ShowInfo("尝试1", pos, 3.0f);
        }
        Debug.Log(Time.realtimeSinceStartup - nowTime);//0.018
        */


        /*
        MsgTipsLogic.getInstance().ShowInfo("尝试1", pos, 3.0f);
        MsgTipsLogic.getInstance().ShowInfo("尝试2", pos, 3.0f);
        MsgTipsLogic.getInstance().ShowInfo("尝试3", pos, 3.0f);
        MsgTipsLogic.getInstance().ShowInfo("尝试3", pos, 3.0f);
        MsgTipsLogic.getInstance().ShowInfo("尝试3", pos, 3.0f);
        MsgTipsLogic.getInstance().ShowInfo("尝试3", pos, 3.0f);
        MsgTipsLogic.getInstance().ShowInfo("尝试3", pos, 3.0f);
        MsgTipsLogic.getInstance().ShowInfo("尝试3", pos, 3.0f);
        */



    }

    private void resetGameOj(GameObject obj)
    {
        Debug.Log("resetGameOj " + obj.name);
    }

    private void TestTween()
    {
        GameObject obj = GameObject.Find("Cube");

        //键值对儿的形式保存iTween所用到的参数
        Hashtable args = new Hashtable();

        //这里是设置类型，iTween的类型又很多种，在源码中的枚举EaseType中
        //例如移动的特效，先震动在移动、先后退在移动、先加速在变速、等等
        args.Add("easeType", iTween.EaseType.easeInOutExpo);

        //移动的速度，
        //args.Add("speed",10f);
        //移动的整体时间。如果与speed共存那么优先speed
        args.Add("time", 2.0f);
        //这个是处理颜色的。可以看源码的那个枚举。
        args.Add("NamedValueColor", "_SpecColor");
        //延迟执行时间
        args.Add("delay", 0.1f);
        //移动的过程中面朝一个点
        args.Add("looktarget", Vector3.zero);

        //三个循环类型 none loop pingPong (一般 循环 来回)	
        args.Add("loopType", "none");
        //args.Add("loopType", "loop");	
        //args.Add("loopType", "pingPong");

        //处理移动过程中的事件。
        //开始发生移动时调用AnimationStart方法，5.0表示它的参数
        args.Add("onstart", "AnimationStart");
        args.Add("onstartparams", 5.0f);
        //设置接受方法的对象，默认是自身接受，这里也可以改成别的对象接受，
        //那么就得在接收对象的脚本中实现AnimationStart方法。
        args.Add("onstarttarget", obj);


        //移动结束时调用，参数和上面类似
        args.Add("oncomplete", "AnimationEnd");
        args.Add("oncompleteparams", "end");
        args.Add("oncompletetarget", obj);


        //移动中调用，参数和上面类似
        args.Add("onupdate", "AnimationUpdate");
        args.Add("onupdatetarget", obj);
        args.Add("onupdateparams", true);



        // x y z 标示移动的位置。

        args.Add("x", 2);
        args.Add("y", 0);
        args.Add("z", 0);

        //当然也可以写Vector3
        //args.Add("position",Vectoe3.zero);


        //最终让改对象开始移动
        iTween.MoveTo(obj, args);
    }

    //对象移动中调用
    //void AnimationUpdate(bool f)
    //{
    //    Debug.Log("update :" + f);
    //}
    ////对象开始移动时调用
    //void AnimationStart(float f)
    //{
    //    Debug.Log("start :" + f);
    //}
    ////对象移动时调用
    //void AnimationEnd(string f)
    //{
    //    Debug.Log("end : " + f);
    //}




    XmlNodeList nodeList1;
    private void loadXML()
    {
        string filepath;
        filepath = Application.dataPath + "/Resources/XMLFiles" + "/FightXml.xml";

        XmlDocument xmlDoc = new XmlDocument();

        if (File.Exists(filepath))
        {
            xmlDoc.Load(filepath);
            nodeList1 = xmlDoc.SelectNodes("Root/FightProcess");

            AttackVo attackVo = new AttackVo(xmlDoc);
        }

        /*
        XmlNode node1 = nodeList1[0];
        int count1 = node1.Attributes.Count;
        Debug.Log("##" + node1.Name + "##");
        for (int i = 0; i < count1;i++ )
        {
            Debug.Log(node1.Attributes[i].Name + "=" + node1.Attributes[i].Value);
        }

        XmlNodeList nodeList2 = xmlDoc.SelectNodes("Root/FightProcess/FightInfo");
        XmlNode node2 = nodeList2[0];
        int count2 = node2.Attributes.Count;
        Debug.Log("##" + node2.Name + "##");
        for (int i = 0; i < count2; i++)
        {
            Debug.Log(node2.Attributes[i].Name + "=" + node2.Attributes[i].Value);
        }

        int count3 = node2.ChildNodes.Count;
        XmlNodeList childNode1 = node2.ChildNodes;
        for (int j = 0; j < count3; j++)
        {
            int count4 = childNode1[j].Attributes.Count;
            Debug.Log("##" + childNode1[j].Name + "##");
            for (int k = 0; k < count4;k++ )
            {
                Debug.Log(childNode1[j].Attributes[k].Name + "=" + childNode1[j].Attributes[k].Value);
            }
        }
        */


        /*
        XmlNodeList nodeList3 = xmlDoc.SelectNodes("Root/FightProcess/Bout");

        for (int m = 0; m < nodeList3.Count;m++ )
        {
            XmlNode node3 = nodeList3[m];
            int count5 = node3.Attributes.Count;
            Debug.Log("##" + node3.Name + "##");
            for (int i = 0; i < count5; i++)
            {
                Debug.Log(node3.Attributes[i].Name + "=" + node3.Attributes[i].Value);
            }


            XmlNodeList nodeList4 = node3.SelectNodes("BoutInfo");
            Debug.Log("##" + nodeList4[0].Name + "##");
            int count6 = nodeList4[0].ChildNodes.Count;
            XmlNodeList childNode2 = nodeList4[0].ChildNodes;
            for (int j = 0; j < count6; j++)
            {
                int count4 = childNode2[j].Attributes.Count;
                Debug.Log("##" + childNode2[j].Name + "##");
                for (int k = 0; k < count4; k++)
                {
                    Debug.Log(childNode2[j].Attributes[k].Name + "=" + childNode2[j].Attributes[k].Value);
                }
            }


            XmlNodeList nodeList5 = node3.SelectNodes("BoutBufferDamage");
            Debug.Log("##" + nodeList5[0].Name + "##");
            int count7 = nodeList5[0].ChildNodes.Count;
            XmlNodeList childNode3 = nodeList5[0].ChildNodes;
            for (int j = 0; j < count7; j++)
            {
                int count8 = childNode3[j].Attributes.Count;
                Debug.Log("##" + childNode3[j].Name + "##");
                for (int k = 0; k < count8; k++)
                {
                    Debug.Log(childNode3[j].Attributes[k].Name + "=" + childNode3[j].Attributes[k].Value);
                }
            }


            XmlNodeList nodeList6 = node3.SelectNodes("Flow");
            for (int n = 0; n < nodeList6.Count;n++ )
            {
                Debug.Log("##" + nodeList6[n].Name + "##");
                int count11 = nodeList6[n].Attributes.Count;
                for (int k = 0; k < count11; k++)
                {
                    Debug.Log(nodeList6[n].Attributes[k].Name + "=" + nodeList6[n].Attributes[k].Value);
                }


                int count9 = nodeList6[n].ChildNodes.Count;
                XmlNodeList childNode4 = nodeList6[n].ChildNodes;
                for (int j = 0; j < count9; j++)
                {
                    int count10 = childNode4[j].Attributes.Count;
                    Debug.Log("##" + childNode4[j].Name + "##");
                    for (int k = 0; k < count10; k++)
                    {
                        Debug.Log(childNode4[j].Attributes[k].Name + "=" + childNode4[j].Attributes[k].Value);
                    }
                }
            }
        }
        */





        //Debug.Log(node.ChildNodes[0].Attributes[0].Value);
        //Debug.Log(node.ChildNodes[0].Attributes["name"].Value);

        //int index = nodeList.Count;

        //for (int i = 0; i < index;i++ )
        //{
        //    XmlNode node = nodeList[i];
        //    XmlNodeList childNode = node.ChildNodes;

        //    for (int j = 0; j < childNode.Count; j++)
        //    {
        //        Debug.Log(childNode[j].Value);
        //    }
        //}


    }


    public void addFunc(object recNum, object recValue)
    {
        Debug.Log(recNum.ToString() + " " + ((ArrayList)recValue).Count);
    }

    public void removeFunc(object recNum, object recValue)
    {
        Debug.Log(recNum.ToString() + " " + ((ArrayList)recValue).Count);
    }


    public void changeProp(object propertyName, object propertyValue)
    {
        Debug.Log("changed " + propertyName.ToString() + " " + propertyValue.ToString());
    }


    public void changeName(string propertyName, string propertyValue)
    {
        Debug.Log("changed " + propertyName + " " + propertyValue);
        //		Debug.Log(ModelLocator.getInstance().scene.GetProperties("name"));
        Debug.Log(ModelLocator.getInstance().scene.Role.GetProperties("name"));
    }




    public string lab11 = "192.168.1.254";
    public string lab10 = "12900";

    public string lab1 = "对象类型";
    public string lab2 = "子类型";
    public string lab3 = "是否属于玩家东西";

    public string lab4 = "对象ID";

    public string lab5 = "对象ID";
    public string lab6 = "字段名";
    public string lab7 = "值类型";
    public string lab8 = "值";

    void OnGUI()
    {
        lab11 = GUI.TextField(new Rect(110, 10, 50, 20), lab11, 25);
        lab10 = GUI.TextField(new Rect(110, 40, 50, 20), lab10, 25);
        if (GUI.Button(new Rect(10, 10, 100, 50), "connect"))
        {
            //SoundManage.getInstance().stopBG();
            gameObject.GetComponent<NetWorkToServer>().ConnectEX(lab11, int.Parse(lab10));//12900
        }
        if (GUI.Button(new Rect(10, 70, 100, 50), "send1"))
        {

            ByteArrayEx byt = new ByteArrayEx();
            byt.writeInt((int)SystemMsgFlag.MESSAGE_CHECK);
            byt.writeByte((byte)SystemMsgFlag.MESSAGE_CHECKCONTENT);
            MySocket.getInstance().Async_Send(byt.byteArray);

            ByteArrayEx byt1 = new ByteArrayEx();
            byt1.writeInt(2);
            byt1.writeInt(1);
            byt1.writeMultiByteEx("gf");
            byt1.writeMultiByteEx("123");
            MySocket.getInstance().Async_Send(byt1.byteArray);
        }
        if (GUI.Button(new Rect(10, 130, 100, 50), "send2"))
        {
            ByteArrayEx byteArray = new ByteArrayEx();

            byteArray.writeInt((int)SystemMsgFlag.NetMessageCS.NM_CS_ROLE_CREATE_SYN);
            byteArray.writeMultiByteEx("gf");							//s玩家姓名s
            byteArray.writeByte(1);							            //s职业s
            byteArray.writeByte(1);									    //s性别s
            byteArray.writeMultiByteEx("female_01");					//s头像名s

            MySocket.getInstance().Async_Send(byteArray.byteArray);
        }

        lab1 = GUI.TextField(new Rect(110, 250, 50, 20), lab1, 25);
        lab2 = GUI.TextField(new Rect(110, 270, 50, 20), lab2, 25);
        lab3 = GUI.TextField(new Rect(110, 290, 50, 20), lab3, 25);
        if (GUI.Button(new Rect(10, 250, 100, 50), "CreateObject"))
        {
            ByteArrayEx byteArray = new ByteArrayEx();

            byteArray.writeInt((int)SystemMsgFlag.NetMessageCS.NM_CS_CREATE_OBJECT);
            byteArray.writeByte((byte)int.Parse(lab1));
            byteArray.writeInt(int.Parse(lab2));
            byteArray.writeByte((byte)int.Parse(lab3));
            MySocket.getInstance().Async_Send(byteArray.byteArray);
        }

        if (GUI.Button(new Rect(10, 190, 100, 50), "CreateRole"))
        {

            ByteArrayEx byteArray = new ByteArrayEx();

            byteArray.writeInt((int)SystemMsgFlag.NetMessageCS.NM_CS_CREATE_PLAYER);
            MySocket.getInstance().Async_Send(byteArray.byteArray);
        }

        lab4 = GUI.TextField(new Rect(110, 330, 50, 20), lab4, 25);
        if (GUI.Button(new Rect(10, 310, 100, 50), "DelObj"))
        {

            ByteArrayEx byteArray = new ByteArrayEx();

            byteArray.writeInt((int)SystemMsgFlag.NetMessageCS.NM_CS_DELETE_OBJECT);
            byteArray.writeUInt64(UInt64.Parse(lab4));
            MySocket.getInstance().Async_Send(byteArray.byteArray);
        }

        lab5 = GUI.TextField(new Rect(110, 370, 50, 20), lab5, 25);
        lab6 = GUI.TextField(new Rect(110, 390, 50, 20), lab6, 25);
        lab7 = GUI.TextField(new Rect(110, 410, 50, 20), lab7, 25);
        lab8 = GUI.TextField(new Rect(110, 430, 50, 20), lab8, 25);
        if (GUI.Button(new Rect(10, 370, 100, 50), "ChangeObj"))
        {

            ByteArrayEx byteArray = new ByteArrayEx();

            byteArray.writeInt((int)SystemMsgFlag.NetMessageCS.NM_CS_MODIFY_OBJECT);
            byteArray.writeUInt64(UInt64.Parse(lab5));
            byteArray.writeMultiByteEx(lab6);
            byteArray.writeByte(byte.Parse(lab7));
            switch (int.Parse(lab7))
            {
                case 1:
                    byteArray.writeByte(byte.Parse(lab8));
                    break;
                case 2:
                    byteArray.writeInt(int.Parse(lab8));
                    break;
                case 6:
                    byteArray.writeMultiByteEx(lab8);
                    break;
                case 8:
                    byteArray.writeUInt64(UInt64.Parse(lab8));
                    break;
            }
            MySocket.getInstance().Async_Send(byteArray.byteArray);
        }


        if (GUI.Button(new Rect(400, 10, 100, 50), "Test"))
        {
            ByteArrayEx byt = new ByteArrayEx();
            byt.writeInt(12);
            byt.writeInt(3);
            byt.writeInt(4);
            MySocket.getInstance().test(byt.byteArray);
        }
        if (GUI.Button(new Rect(400, 60, 100, 50), "Test2"))
        {
            ByteArrayEx byt = new ByteArrayEx();
            byt.writeInt(8);

            byt.writeInt(8);
            byt.writeInt(1);
            byt.writeInt(2);

            byt.writeInt(4);
            MySocket.getInstance().test(byt.byteArray);
        }
        if (GUI.Button(new Rect(400, 110, 100, 50), "Test3"))
        {
            ByteArrayEx byt = new ByteArrayEx();
            byt.writeInt(11);
            MySocket.getInstance().test(byt.byteArray);
        }

        //if (GUI.Button (new Rect (100, 200, 100, 50), "OpenBox")) {

        //    //string path = EditorUtility.SaveFilePanel("导出为Excel文件", "", "scene", "xls");
        //    EditorUtility.DisplayDialog("提示", "123", "OK");
        //}



        if (GUI.Button(new Rect(400, 170, 100, 50), "Server1"))
        {
            ByteArrayEx byt = new ByteArrayEx();
            byt.writeInt(0);
            byt.writeByte(1);
            MySocket.getInstance().Async_Send(byt.byteArray);
        }
        if (GUI.Button(new Rect(400, 220, 100, 50), "Server2"))
        {
            ByteArrayEx byt = new ByteArrayEx();
            byt.writeInt(2);
            byt.writeInt(1);
            byt.writeMultiByteEx("gf");
            byt.writeMultiByteEx("中");
            MySocket.getInstance().Async_Send(byt.byteArray);
        }
        if (GUI.Button(new Rect(400, 270, 100, 50), "Server3"))
        {
            ByteArrayEx byt = new ByteArrayEx();
            byt.writeInt(5);
            byt.writeInt(11);
            byt.writeInt(12);
            byt.writeInt(13);
            MySocket.getInstance().Async_Send(byt.byteArray);
        }





    }

    void OnApplicationQuit()
    {
        MySocket.getInstance().OnApplicationQuit();
    }
}
